package com.hgh.nettydemo.netty.nettyclient.protocolInitalizer;

import com.hgh.nettydemo.netty.nettyclient.handler.ClientMessageHandler;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.codec.string.StringEncoder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author: huguanghui
 * Created by huguanghui on 2018/6/18.
 * @Description:
 */
@Component("clientMessageProtocolInitalizer")
public class ClientMessageProtocolInitalizer extends ChannelInitializer<SocketChannel> {



    @Autowired
    private ClientMessageHandler clientMessageHandler;
    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {
        ChannelPipeline pipeline = socketChannel.pipeline();
        pipeline.addLast("decoder", new StringDecoder());
        pipeline.addLast("encoder", new StringEncoder());
        pipeline.addLast("handler", clientMessageHandler);
    }
}
